import { stringify } from 'qs';
import request from '@/utils/request';
import apiPath from '@/configs/api.map';

const {
  api_editPassword,
  api_login,
  api_editUser,
  api_resetPassword,
  api_currentUser,
  api_queryUserPermissions,
  api_diffPassword,
  api_queryUserNavs,
  api_loginCheck,
  api_validateToken,
} = apiPath;
/**
 * @description 登录
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function login(params) {
  return request(api_login, {
    method: 'POST',
    data: params,
  });
}

/**
 * @description 修改密码
 * @author songs
 * @date 2019-08-27
 * @export
 * @param {*} params
 * @returns
 */
export async function setPassword(params) {
  return request(api_editPassword, {
    method: 'POST',
    data: params,
  });
}

/**
 * @description 更新用户信息
 * @author songs
 * @date 2019-09-12
 * @export
 * @param {*} params
 * @returns
 */
export async function updataUserInfo(params) {
  return request(api_editUser, {
    method: 'POST',
    data: params,
  });
}

/**
 * @description 更新用户信息
 * @author songs
 * @date 2019-09-12
 * @export
 * @param {*} params
 * @returns
 */
export async function resetPassword(params) {
  return request(api_resetPassword, {
    method: 'POST',
    data: params,
  });
}

/**
 * @description 初始化用户
 * @author songs
 * @date 2019-09-12
 * @export
 * @param {*} params
 * @returns
 */
export async function init(params) {
  return request('/admin/api/init', {
    method: 'POST',
    data: params,
  });
}

export async function queryCurrent(params) {
  return request(`${api_currentUser}?${stringify(params)}`);
}

export async function queryUserPermissions(params = {}) {
  return request(`${api_queryUserPermissions}?${stringify(params)}`);
}

export async function queryUserNavs(params = {}) {
  return request(`${api_queryUserNavs}?${stringify(params)}`);
}

export async function loginOut() {
  return request('/admin/api/loginOut', {
    method: 'POST',
  });
}

export async function diffPassword(params) {
  return request(api_diffPassword, {
    method: 'POST',
    data: params,
  });
}

export async function loginCheck(params) {
  return request(api_loginCheck, {
    method: 'POST',
    data: params,
  });
}

export async function validateToken(params) {
  return request(api_validateToken, {
    method: 'POST',
    data: params,
  });
}
